﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net;
using System.IO;
using System.Web.UI.HtmlControls;
using System.Configuration;

namespace GetData
{
    public partial class CallPostMethodIdeas : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                setValueInTextBox();
            }
        }

        protected void btnTest_Click(object sender, EventArgs e)
        {
           
            string postData;
            HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(Convert.ToString(ConfigurationManager.AppSettings["PostUrl"])+"getIdeas");
            postData = "dwell_priority_kl_loc=" + txtdwell_priority_kl_loc.Text + "/feature_string=" + txtfeature_string.Text + "/ps_goal_string=" + txtps_goal_string.Text + "/turn_offs=" + txtturn_offs.Text + "/startmonth=" + txtstartmonth.Text + "/startyear=" + txtstartyear.Text + "/requestedmonth=" + txtrequestedmonth.Text + "/requestedyear=" + txtrequestedyear.Text;
           //postData = "dwell_priority_kl_loc=1,1,1,US,IL_N/feature_string=ACC,FAHD,GFB,WHG,FP,WA,DY,DWSH,GD,REF,STV,OVN,MW,ATT,ROOF,RG,BSMT,FDN,SPX,GAR,EGF,PLB,DOOR,WIND,WS,LWN,DKG,PF,BBQ,WSD,OWF,DWY,OLIT,HL,SPTC,CF,WF,CPTS,DVB,FURW,FURL,FURU,MAT,BATH,KITC,CLST,LITE,SD,COD,FE,EMS,PC,SS,MED,EAUD,ENR,GARR,INR,MGR,TAXR,TELR,CGD/ps_goal_string=1,1,2,2,2,2,1,1,2,0,0,0/turn_offs=/startmonth=11/startyear=2013/requestedmonth=11/requestedyear=2013";
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] data = encoding.GetBytes(postData);

            httpWReq.Method = "POST";
            httpWReq.ContentType = "application/x-www-form-urlencoded";
            httpWReq.ContentLength = data.Length;

            using (Stream stream = httpWReq.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
            string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            lblResponse.Text = responseString;
            setValueInSession();
        }
        protected void setValueInTextBox()
        {
            if (Session["dwell_priority_kl_loc"] != null)
            {
                txtdwell_priority_kl_loc.Text = Session["dwell_priority_kl_loc"].ToString();
            }
            if (Session["feature_string"] != null)
            {
                txtfeature_string.Text = Session["feature_string"].ToString();
            }
            if (Session["ps_goal_string"] != null)
            {
                txtps_goal_string.Text = Session["ps_goal_string"].ToString();
            }
            if (Session["turn_offs"] != null)
            {
                txtturn_offs.Text = Session["turn_offs"].ToString();
            }
            if (Session["startmonth"] != null)
            {
                txtstartmonth.Text = Session["startmonth"].ToString();
            }
            if (Session["startyear"] != null)
            {
                txtstartyear.Text = Session["startyear"].ToString();
            }
            if (Session["requestedmonth"] != null)
            {
                txtrequestedmonth.Text = Session["requestedmonth"].ToString();
            }
            if (Session["requestedyear"] != null)
            {
                txtrequestedyear.Text = Session["requestedyear"].ToString();
            }
        }
        protected void setValueInSession()
        {
            Session["dwell_priority_kl_loc"] = txtdwell_priority_kl_loc.Text;
            Session["feature_string"] = txtfeature_string.Text;
            Session["ps_goal_string"] = txtps_goal_string.Text;
            Session["turn_offs"] = txtturn_offs.Text;
            Session["startmonth"] = txtstartmonth.Text;
            Session["startyear"] = txtstartyear.Text;
            Session["requestedmonth"] = txtrequestedmonth.Text;
            Session["requestedyear"] = txtrequestedyear.Text;
        }
    }
}